home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / et / et3_0-a1.lha / et3 / src / TextFormatter.h < prev    next >
C/C++ Source or Header  |  1992-05-08  |  3KB  |  145 lines

  1. #ifndef TextFormatter_First
  2. #ifdef __GNUG__
  3. //pragma once
  4. #pragma interface
  5. #endif
  6. #define TextFormatter_First
  7.  
  8. #include "Object.h"
  9. #include "Font.h"
  10. #include "Mark.h"
  11.  
  12. //---- descriptor of a text line -----------------------------------------
  13.  
  14. struct LineDesc {
  15.     int lnAscent;
  16.     int lnHeight;
  17.     LineDesc(int b= 0, int h= 0);
  18.     void Reset();
  19.  
  20.     bool IsEqual(LineDesc l);
  21.     void Max(Font *f);
  22.     void Max(LineDesc ld);
  23.     void Max(int ascent, int height);
  24.  
  25.     void FromFont(Font *f);
  26.     int Height();
  27.     int Base();
  28. };
  29.  
  30. //---- line mark ------------------------------------------------------------
  31.  
  32. struct LineMark: public Mark {
  33.     LineDesc ld;
  34.  
  35.     MetaDef(LineMark);
  36.  
  37.     LineMark(LineDesc ldesc, int pos= 0, int len= 0, eMarkState s= eStateNone);
  38.     LineMark();
  39.     void ChangeMark(int pos, int len, LineDesc ldesc, eMarkState s= eStateNone);
  40.     void Copy(LineMark*);
  41.     int Height();
  42.     int Base();
  43.     bool IsDifferent(LineMark *lm);
  44. };
  45.  
  46. //---- abstract class TextFormatter ---------------------------------------
  47.  
  48. class ObjArray;
  49. class Text;
  50. class TextPainter;
  51.  
  52. class TextFormatter: public Object {
  53. public:
  54.     MetaDef(TextFormatter);
  55.     TextFormatter();
  56.     
  57.     int Format(Text *, TextPainter *tp, int w, int from, int to);
  58.     ObjArray *GetLines();
  59.     static void Free();
  60.     
  61. protected:
  62.     static ObjArray *lines;
  63.     static int nLines;
  64.     
  65.     void AddBreak(Text *t, TextPainter *tp, int from, int to, LineDesc &ld);
  66.     virtual void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
  67. };
  68.  
  69. //---- SimpleFormatter, break lines only at breaking characters (\n, \r, \f) --
  70.  
  71. class SimpleFormatter: public TextFormatter {
  72. public:
  73.     MetaDef(SimpleFormatter);
  74.     SimpleFormatter();
  75.     
  76. protected:
  77.     void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
  78. };
  79.  
  80. //---- FoldingFormatter, fold lines (preemptive) -------------------------
  81.  
  82. class FoldingFormatter: public TextFormatter {
  83. public:
  84.     MetaDef(FoldingFormatter);
  85.     FoldingFormatter();
  86.  
  87. protected:
  88.     void DoFormat(Text *, TextPainter *tp, int w, int from, int to);
  89.     
  90.     void BreakCharacter(Text *t, TextPainter *tp, int at, LineDesc &maxld, int w);
  91.     void BreakWord(Text *t, TextPainter *tp, LineDesc &maxld, int w);
  92.     void Break(TextPainter *tp, int from, int to, LineDesc &maxld, int w);
  93.  
  94. private:
  95.     Text *text;
  96.     int start, end, width, nWords, wx, cx;
  97. };
  98.  
  99. //---- abstract class TextPager ------------------------------------------
  100.  
  101. class TextPager: public Object {
  102. public:
  103.     MetaDef(TextPager);
  104.     TextPager();
  105.     virtual Rectangle NextPageBreak(int pn, Rectangle pgr, class StaticTextView *);
  106.     virtual void Repaginate(int startAt);
  107. };
  108.  
  109. //---- abstract class LinePager ------------------------------------------
  110.  
  111. class LinePager: public TextPager {
  112. public:
  113.     LinePager();
  114.     Rectangle NextPageBreak(int pn, Rectangle pgr, class StaticTextView *);
  115. };
  116.  
  117. //---- inlines -----------------------------------------------------------
  118.  
  119. inline bool LineDesc::IsEqual(LineDesc l)
  120. {
  121.     return lnAscent == l.lnAscent && lnHeight == l.lnHeight;
  122. }
  123.  
  124. inline int LineDesc::Height()
  125. {
  126.     return lnHeight;
  127. }
  128.  
  129. inline int LineDesc::Base()
  130. {
  131.     return lnAscent;
  132. }
  133.  
  134. inline int LineMark::Height()
  135. {
  136.     return ld.Height();
  137. }
  138.  
  139. inline int LineMark::Base()
  140. {
  141.     return ld.Base();
  142. }
  143.  
  144. #endif
  145.